import datetime

import requests
from flask import Flask,request

app = Flask(__name__)

@app.route('/question',methods=['POST'])
def hello_world():
    formData = request.form
    formDict = formData.to_dict()
    print(formDict)
    writeQ(str(formDict))
    return 'ok'
@app.route('/log',methods=['POST'])
def hello_worldd():
    formData = request.form
    formDict = formData.to_dict()
    print(formDict)
    writeLog(str(formDict))
    return 'ok'

def writeLog(text):
    now_time = datetime.datetime.now()
    filename = 'log.txt'
    with open(filename, 'a',encoding="utf-8") as file_object:
        time_str = datetime.datetime.strftime(now_time, '%Y-%m-%d %H:%M:%S')
        file_object.write(time_str + "-")
        file_object.write(str(text) + "\n")
def writeQ(text):
    now_time = datetime.datetime.now()
    filename = 'logq.txt'
    with open(filename, 'a',encoding="utf-8") as file_object:
        time_str = datetime.datetime.strftime(now_time, '%Y-%m-%d %H:%M:%S')
        file_object.write(time_str + "-")
        file_object.write(str(text) + "\n")


if __name__ == '__main__':
     app.run()

